package from;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.PageableListView;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.model.PropertyModel;

import java.util.ArrayList;
import java.util.List;

public class PageableListPage extends WebPage {
    private static List Books = new ArrayList();

    static {
        for (int i = 0; i < 100; i++) {
            Book book = new Book();
            book.setId(i);
            book.setAuthor("author" + i);
            book.setTitle("title" + i);

            Books.add(book);
        }
    }

    public PageableListPage(){
        super();

        final PageableListView listView = new PageableListView("books",Books,10) {
            @Override
            protected void populateItem(ListItem item) {
                final Book book = (Book) item.getModelObject();
                item.add(new CheckBox("selected",new PropertyModel<>(book,"selected")));
                item.add(new Label("id",Integer.toString(book.getId())));
                item.add(new Label("title",book.getTitle()));
                item.add(new Label("author",book.getAuthor()));
                item.add(new SubmitLink("edit") {
                    public void onClick(){

                    }
                });
            }
        };
        Form form = new Form("formPL"){
            protected void onSubmit(){

            }
        };
        this.add(form);
        form.add(listView);

        form.add(new PagingNavigator("navigator",listView));
    }
}
